<?php

class Adresse extends Feld {
	
	public $id;
	public $typ;
	public $label;
	public $labelling;
	public $felder;
	
	public function Adresse($id,$typ,$label,$labelling,$felder){
		$this->id = $id;
		$this->typ = $typ;
		$this->label = $label;
		$this->labelling = $labelling;
		$this->felder = $felder;
		//print_r($felder);
	}
	
	public function getCode($wert=null,$label=null,$fehler=null){
		?>
		
		<tr>
			<td><?php echo $this->typ ?></td>
			<td><input type='text' name='<?php echo $this->id ?>label' value='<?php echo $this->label ?>' /></td>
			<td><input type='hidden' name='<?php echo $this->id ?>' value='nodelete' /></td>
		</tr>
		
		<?php
		//print_r($this->felder);
		foreach($this->felder AS $feld){
	  		if(!isset($_SESSION["Fehler"][$feld->id])) {
	  			$feld->getCode(); 
	  		} else {
	  			$feld->getCode($_SESSION["FehlerPost"][$feld->id],$_SESSION["FehlerPost"][$feld->id."label"],$_SESSION["Fehler"][$feld->id]);
	  		} 		
	  	}
	  	
	  	$urlParameter = rawurlencode(utf8_encode($this->toString()));
	  	
	  	?>
	  	<tr>
	  		<td></td>
	  		<td></td>
	  		<td>
	  			<img src="http://maps.google.com/maps/api/staticmap?center=<?php echo $urlParameter ?>&size=400x300&markers=color:white|<?php echo $urlParameter ?>&sensor=false" alt="karte" />
	  		<td>
	  	
	  	<?php
		
	}
	
	public function getVCard($nummer){
		$strasse;
		$hausnr;
		$plz;
		$ort;
		
		foreach($this->felder AS $feld){
			switch($feld->typ){
				case "Strasse":
					$strasse = $feld->value;
					break;
				case "Hausnummer":
					$hausnr = $feld->value;
					break;
				case "PLZ":
					$plz = $feld->value;
					break;
				case "Ort":
					$ort = $feld->value;
					break;
			}
		}
		
		//print_r($this->felder);
		return "item$nummer.ADR;TYPE=HOME:;;$strasse $hausnr;$ort;;$plz;\r\nitem$nummer.X-ABLabel:".$this->label."\r\n";
	}
	
	public static function validate(){
		return null;
	}
	
	public function toString(){
		
		$strasse;
		$hausnr;
		$plz;
		$ort;
		
		foreach($this->felder AS $feld){
			switch($feld->typ){
				case "Strasse":
					$strasse = $feld->value;
					break;
				case "Hausnummer":
					$hausnr = $feld->value;
					break;
				case "PLZ":
					$plz = $feld->value;
					break;
				case "Ort":
					$ort = $feld->value;
					break;
			}
		}
		
		return "$strasse $hausnr\r\n$plz $ort";
	
	}
	
}

?>